package com.myframework.utils.logutil;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.PropertyConfigurator;

public class WMLogger {
	
	private static Logger logger;
	// Level.ALL < Level.DEBUG < Level.INFO < Level.WARN < Level.ERROR < Level.FATAL < Level.OFF
	public final static String LEVEL_ALL = "ALL";
	public final static String LEVEL_DEBUG = "DEBUG";
	public final static String LEVEL_INFO = "INFO";
	public final static String LEVEL_WARN = "WARN";
	public final static String LEVEL_ERROR = "ERROR";
	public final static String LEVEL_FATAL = "FATAL";
	public final static String LEVEL_OFF = "OFF";
	
	public static void setLevel(String level) {
		if (WMLogger.LEVEL_ALL.equals(level)) {
			logger.setLevel(Level.ALL);
		} else if (WMLogger.LEVEL_DEBUG.equals(level)) {
			logger.setLevel(Level.DEBUG);
		} else if (WMLogger.LEVEL_INFO.equals(level)) {
			logger.setLevel(Level.INFO);
		} else if (WMLogger.LEVEL_WARN.equals(level)) {
			logger.setLevel(Level.WARN);
		} else if (WMLogger.LEVEL_ERROR.equals(level)) {
			logger.setLevel(Level.ERROR);
		} else if (WMLogger.LEVEL_FATAL.equals(level)) {
			logger.setLevel(Level.FATAL);
		} else if (WMLogger.LEVEL_OFF.equals(level)) {
			logger.setLevel(Level.OFF);
		}
	}
	
	public static void debug(Object message) {
		logger.debug(message);
	}
	
	public static void info(Object message) {
		logger.info(message);
	}
	
	public static void warn(Object message) {
		logger.warn(message);
	}
	
	public static void error(Object message) {
		logger.error(message);
	}
	
	public static void fatal(Object message) {
		logger.fatal(message);
	}
	
	public static void debug(Object message, Throwable t) {
		logger.debug(message, t);
	}
	
	public static void info(Object message, Throwable t) {
		logger.info(message, t);
	}
	
	public static void warn(Object message, Throwable t) {
		logger.warn(message, t);
	}
	
	public static void error(Object message, Throwable t) {
		logger.error(message, t);
	}
	
	public static void fatal(Object message, Throwable t) {
		logger.fatal(message, t);
	}
	
	public static void init() {
		logger = Logger.getLogger(WMLogger.class.getName());
	}

}
